// pages/liuyan/liuyan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sysConfig: null,
    msg_alopecia_index: 0,
    msg_connect_index: 0,
    protocol: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.$model.home.sysConfig().then((res) => {
      this.setData({
        sysConfig: res
      })
    });
  },

  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    const index = e.detail.value;
    const type = e.currentTarget.dataset.type;
    this.setData({
      [type]: index
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 用户点击右上角分享朋友圈
   */
  onShareTimeline: function () {
    return this.onShareAppMessage();
  },

  // 马上提交
  onSubmit: function (e) {
    console.log(e);
    if (!this.data.protocol) {
      wx.showToast({
        title: '请同意协议',
        icon: 'none'
      })
      return
    }

    const values = e.detail.value;
    values.alopecia = this.data.sysConfig.msg_alopecia[this.data.msg_alopecia_index];
    values.connect = this.data.sysConfig.msg_connect[this.data.msg_connect_index];

    wx.$http.post('message/submit', values).then(function (res) {
      wx.showModal({
        content: '已提交',
        showCancel: false,
      })
    });
  },
  protocolChange () {
    this.setData({
      protocol: !this.data.protocol
    })
  },
  goProtocol (e) {
    const type = e.target.dataset.type

    wx.navigateTo({
      url: '/pages/protocol/protocol?type=' + type,
    })
  }
})